/*  ----------------------------------------------------------------------------
*	This file is part of the AS3This ActionScript 3 library.
*	Author: Steve Jones for G-RAFF <http://www.g-raff.com/>
*	Copyright (c) 2009 raffWorks Ltd.
*	----------------------------------------------------------------------------
*	Please see the notice at the bottom of the code before using or modifying this class.
*/
package com.as3this.core
{
	import flash.geom.Point;
	import com.as3this.interfaces.IShareOptions;
	
	public class RichShareOptions extends ShareOptions implements IShareOptions
	{
		protected var video_src		:String;
		protected var video_width	:Number;
		protected var video_height	:Number;
		protected var image_src		:String;
		protected var _flashvars	:Object;
		
		/**
		 * Constructor
		 *  
		 * @param title		Title of the content eg. "My marvellous widget" or "My nice link"
		 * @param desc		Description of the content
		 * @param video_src	URL of the source SWF
		 * @param width		width of the source SWF
		 * @param height	height of the source SWF
		 * @param image_src	URL of a JPEG, GIF or PNG that serves as a screenshot when sharing. Should be same width and height as the SWF 
		 * 
		 * <p>This extends the <code>ShareOptions</code> class which only accepts a title and description</p>
		 *
		 * @see ShareOptions
		 */
		 
		public function RichShareOptions(title:String=null, desc:String=null, video_src:String = null, width:Number = NaN, height:Number = NaN, image_src:String = null)
		{
			// set the standard options first
			super(title, desc);
			
			// add the additional options
			this.video_src = video_src;
			this.video_width = width;
			this.video_height = height;
			this.image_src = image_src;
		}
		
		/**
		 * Returns a url-encoded query string to specify variables for the SWF.
		 * <p>This makes it easy to make SWFs "in the wild" have dynamic properties</p>
		 */
		
		public function get formattedSwfURL() : String
		{
			if (_flashvars)
			{
				var queryString:String = "";
			
				for (var key:String in _flashvars)
				{
					queryString += key + "=" + _flashvars[key] + "&";
				}
				queryString = queryString.substr(0, queryString.length - 1);
			}
			
			if (queryString.length > 0) return video_src + "?" + queryString;
			
			return video_src;
		}
		
		// SOURCE 
		/**
		 * The source SWF to be shared
		 */
		
		public function set src(url:String) : void
		{
			video_src = url;
		}
		
		public function get src() : String
		{
			return video_src;
		}
		
		// WIDTH 
		
		/**
		 * Width of the source SWF
		 */
		 
		public function set width(w:Number) : void
		{
			video_width = w
		}
		
		public function get width() : Number
		{
			return video_width;
		}
		
		// HEIGHT 
		
		/**
		 * Height of the source SWF
		 */
		 
		public function set height(h:Number) : void
		{
			video_height = h
		}
		
		public function get height() : Number
		{
			return video_height;
		}
		
		// SCREENSHOT
		/**
		 * A JPEG, GIF or PNG that serves as a screenshot for your SWF. Should be the same size as the width / height of the SWF
		 */
		
		public function set screenshot(image_src:String) : void
		{
			this.image_src = image_src;
		}
		
		public function get screenshot() : String
		{
			return image_src;
		}
	
		// FLASHVARS
		/**
		 * Set a dynamic variable that will be passed to the endpoint when sharing the SWF
		 */
		
		public function setFlashvar(name:String, value:*) : void
		{
			if (!_flashvars) _flashvars = new Object();
			_flashvars[name] = value;
		}
		
		/**
		 * The full set of dynamic variables
		 */
		
		public function set flashvars(vars:Object) : void
		{
			_flashvars = vars;
		}
		
		public function get flashvars() : Object
		{
			return _flashvars;
		}
	}
}

/*
 *    AS3This is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    AS3This is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with AS3This.  If not, see <http://www.gnu.org/licenses/>.
 */